Color VariablesΒΆ

This example creates variables for colors that may be referred to in the program by a name, rather than a number.

from p5 import *

def setup():
        size(640, 360)
        no_stroke()
        background(51, 0, 0)

        inside = Color(204, 102, 0)
        middle = Color(204, 153, 0)
        outside = Color(13, 51, 0)

        with push_matrix():
                translate(80, 80)
                fill(outside)
                rect((0, 0), 200, 200)
                fill(middle)
                rect((40, 60), 120, 120)
                fill(inside)
                rect((60, 90), 80, 80)

        with push_matrix():
                translate(80, 80)
                fill(outside)
                rect((0, 0), 200, 200)
                fill(middle)
                rect((40, 60), 120, 120)
                fill(inside)
                rect((60, 90), 80, 80)

if __name__ == '__main__':
  run()